<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title></title>
	<script src="./eejs-api.min.js"></script>
	<style>
	html, body {width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;background: #f0f0f0;}
	.list-box {width: 100%; height: calc(100% - 90px); float: left;}
	.line{ line-height: 32px; width: 100%; margin: 5px; float: left;}
	</style>
</head>

<body>
	<script type="text/javascript">		
		ee.AppConfig({
			"title": "京东自动登录",
			"hideWindow": false, 
			"width": 320, 
			"height": 250, 
			"debug": false,
			"log2file": false,
			"max": false,
			"min": false,
			"close": true,
			"resize": true,
			"border": true,
			"flash": true
		});

		var w = new ee.MyWindow();
		function openWindow(){
			
			w.create({"left": 100, "top": 50, "width": 350, "height": 560, "border": 2}, function(ret){
				createBrowser(ret.handle);
			});
			w.onResize = function(ret){
				b.move({"left": 0, "top": 0, "width": ret.width, "height": ret.height});
			};
		}
		var b = new ee.Browser();
		function createBrowser(handle){			
			b.create({"handle": handle, "left": 0, "top": 0, "width": 350, "height": 560, "alpha": "255", "enableAll": false}, function(ret){
				console.info("--2-->" + ret.handle);
				b.go({"url": "https://passport.jd.com/new/login.aspx?ReturnUrl=https%3A%2F%2Fwww.jd.com%2F%3Fcu%3Dtrue%26utm_source%3Dhao.360.com%26utm_medium%3Dtuiguang%26utm_campaign%3Dt_1000003625_360mz%26utm_term%3D1675ebf5bab0484d90befe9b1e05e039"});
			});

			b.onLoaded = function(ret){
				console.info("==onLoaded==>" + ret.handle);
				b.runjsString({script: "document.title"}, function(aa){
					w.setTitle({"title": aa.result});
				});
				b.runjs({script: "document.querySelector('.login-form').style.float='left'"});	b.runjs({script: "document.querySelector('.login-tab.login-tab-r > a').click()"});	
				b.runjs({script: "document.body.style.overflow='hidden'"});

				$('loginbtn').style.display = 'block';
			}
		}

		function startLogin(){
			var acc = $('acc').value;
			var pwd = $('pwd').value;
			b.runjs({script: "document.querySelector('#loginname').value = '"+acc+"'"});
			b.runjs({script: "document.querySelector('#nloginpwd').value = '"+pwd+"'"}, function(ret){
				b.runjs({script: "document.querySelector('#loginsubmit').click();"});
			});
		}

		function $(id){return document.getElementById(id);}
	</script>

	<div class="line">
		<button onclick="openWindow()">打开京东登录页面</button>
	</div>
	<div class="line">
		<div>账号：<input id="acc" value="test"></div>
		<div>密码：<input id="pwd" value="123456"></div>
	</div>
	<div class="line">		
		<button id="loginbtn" onclick="startLogin()" style="display:none;">开始登录</button>
	</div>	
</body>

</html>